<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


<div class="layui-fluid">
    <div class="layui-card">

            <div class="layui-card-header " style="color:#d02e25;font-family: '楷体'; ">
                组织列表
            </div>

            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item refresh-nav" align="center" style="font-family: '宋体'; font-size: 20px;" >
                    <div class="layui-inline">
                        <label class="layui-form-label" >组织名</label>
                        <div class="layui-input-inline">
                            <input style="height: auto;margin-top: 5px" type="text" id="groupName" name="groupName" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">组织号</label>
                        <div class="layui-input-inline">
                            <input style="height: auto;margin-top: 5px" type="text" id="groupNum" name="groupNum" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline" id="search">
                        <button class="layui-btn" id="searchBtn" data-type="reload">搜索</button>
                    </div>
            </div>
            <div class="layui-card-body">
                <table id="groupList" lay-filter="groupList">

                </table>
            </div>
        </div>
    </div>
</div>







<%-- 查看详情--%>
<div class="layui-hide" id="show-detail">
    <div class="layui-row layui-card-body">
        <div align="center">




        </div>
    </div>
</div>


<script>


    layui.use(['table','form'], function(){
        var table = layui.table
            ,form = layui.form;

        //组织人员列表
        table.render({
            elem: '#groupList'
            // ,height: 'full-200'
            ,method: 'post'
            ,url: '/ajax/party/admin/grouplist'
            ,page: true
            ,loading: true
            ,cellMinWidth: 80
            ,limit: 10
            ,id: 'groupList'
            ,cols: [[
                {field: 'id', title: '组织号', width: 80, sort: true, fixed: 'left'}
                ,{field: 'branchName', title: '组织名 '}
                ,{field: 'number', title: '组织人数'}
                ,{field: 'address', title: '地址'}
                ,{fixed: 'right', title: '操作', align: 'center', width: 200, toolbar: '#dothing' }
            ]]
        });





        //搜索 ----------------------------------------------- Begin-----------------------------------------------------------
        // var $ = layui.$, active =
        //     {
        //         reload: function () {
        //             var groupNum = $('#groupNum').val();//获取输入框的值
        //             var groupName = $("#groupName").val();
        //             if(groupNum == null || groupNum==""){
        //                 groupNum=0;
        //             }
        //             alert(groupNum);
        //             alert(groupName);
        //             //执行重载
        //             table.reload('groupList',
        //                 {
        //                     page:
        //                         {
        //                             curr: 1 //重新从第 1 页开始
        //                         }
        //                     ,limit:10
        //                     ,where: { groupNum: groupNum,
        //                               groupName:groupName}//这里传参  向后台
        //                     ,url: '/ajax/party/admin/serachGroup'//后台做模糊搜索接口路径
        //                     ,method: 'post',
        //                 });
        //         }
        //     };

        layui.$("#searchBtn").click(function () {
            var groupNum = $('#groupNum').val();//获取输入框的值
            var groupName = $("#groupName").val();
            if(groupNum == null || groupNum==""){
                groupNum=0;
            }
            console.log(groupNum);
            console.log(groupName);

            table.reload('groupList',
                {
                    page:
                        {
                            curr: 1 //重新从第 1 页开始
                        }
                    ,limit:10
                    ,where: { groupNum: groupNum,
                        groupName:groupName}//这里传参  向后台
                    ,url: '/ajax/party/admin/serachGroup'//后台做模糊搜索接口路径
                    ,method: 'post',
                });

        });


        // //这个是用于创建点击事件的实例
        // $('#search .layui-btn').on('click', function ()
        // {
        //     var type = $(this).data('type');
        //     active[type] ? active[type].call(this) : '';
        // });
        //搜索






        //监听工具条
        table.on('tool(groupList)', function(obj){
            var data = obj.data;

            if(obj.event === 'detail'){

                $.post('/ajax/party/admin/getOneGroup',{
                    id:data.id
                },function(result){
                    layer.open({
                        type: 1,
                        area: ['1200px','80%'],
                        title: "ID:" + data.id,
                        offset: '10%',
                        anim: 4,
                        shadeClose: true,
                        content: showDetails(result.data)
                    });
                    // update_form_value(result);

                    var check1 = result.data.isHaveFirstsecretary;
                    var check2 = result.data.isHaveEducationplace;
                    var check3= result.data.isHaveParttime;

                    if(check1=="是"){
                        $("#isHaveFirstsecretary").attr("checked",true);
                    }

                    if(check3=="是"){
                        $("#isHaveParttime").attr("checked",true);
                    }

                    if(check2=="是"){
                        $("#isHaveEducationplace").attr("checked",true);
                    }

                    form.render();
                    // console.log(result.data.time);

                    laydate.render({
                        elem: '#establishmentDate',
                        // value:result.data.time,
                        // isInitValue:true
                    })
                    // form.render();
                    $.post("/ajax/party/admin/branches",{
                        check:1024
                    },function (res) {
                        //得到所有级别
                        //输出
                        console.log(res);
                        var index = 0;
                        res = res.data;
                        for(i = 0; i < res.length; i++){
                            if(res[i].branchName == result.data.branchName){
                                var obj=document.getElementById('branchName');
                                obj.options[obj.options.length]=new Option(res[i].branchName,res[i].branchName);
                                $("#branchName>option").eq(obj.options.length-1).attr("selected", true);
                                index = obj.options.length-1;
                            }else {
                                document.getElementById("branchName").options.add(new Option(res[i].branchName,res[i].branchName));
                            }
                        }

                        for(i = 0; i < res.length; i++){
                            if(res[i].branchName == result.data.superiorBranch){
                                var obj=document.getElementById('superiorBranch');
                                obj.options[obj.options.length]=new Option(res[i].branchName,res[i].branchName);
                                $("#superiorBranch>option").eq(obj.options.length-1).attr("selected", true);
                                index = obj.options.length-1;
                            }else {
                                document.getElementById("superiorBranch").options.add(new Option(res[i].branchName,res[i].branchName));
                            }
                        }
                        form.render('select');
                    });
                });

            } else if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    $.post("/ajax/party/admin/delGroup",{
                        id:data.id
                    },function(result){
                        console.log(result);
                        if(result.code==0){
                            layer.alert("删除成功！");
                        }
                        obj.del();
                        layer.close(index);
                    });
                });
            }
        });








        var laydate = layui.laydate;


        form.on('submit(ok)',function (data) {
            if(data.field.isHaveFirstsecretary=="on"){
                data.field.isHaveFirstsecretary = "是";
            }else{
                data.field.isHaveFirstsecretary = "否";
            }

            if(data.field.isHaveParttime=="on"){
                data.field.isHaveParttime = "是";
            }else{
                data.field.isHaveParttime = "否";
            }

            if(data.field.isHaveEducationplace=="on"){
                data.field.isHaveEducationplace = "是";
            }else{
                data.field.isHaveEducationplace = "否";
            }


            $.ajax({
                type:"post",
                url:"/ajax/party/admin/addgroup",
                contentType : 'application/json;charset=utf-8',
                //设置请求头信息
                dataType:"json",
                data:JSON.stringify(data.field),
                success:function (res) {
                    if(res.code==0){
                        layer.alert("OK");
                        // refresh();

                    }
                }
            })

            return false;
        })


    });
</script>




<script type="application/javascript">
    function showDetails(data) {


    var s = '<form class="layui-form" id="form1">\n' +
        '                <div class="layui-card">\n' +
        '                    <div class="layui-card-body">\n' +
        '                        <div class="layui-form-item">\n' +
        '                            <label class="layui-form-label">组织号</label>\n' +
        '                            <div class="layui-input-inline">\n' +
        '                                <input type="text" name="id" value='+ data.id +' lay-verify="required"\n' +
        '                                       autocomplete="off" class="layui-input">\n' +
        '                            </div>\n' +
        '\n' +
        '                            <label class="layui-form-label">组织名</label>\n' +
        '                            <div class="layui-input-inline">\n' +
        '                                <div class="layui-inline" style="width: 100%;">\n' +
        '\n' +
        '                                    <div class="layui-input-inline" style="width: 100%;">\n' +
        '                                        <select name="branchName" id="branchName"  lay-verify="required" lay-search="" style="width: 100%;">\n' +
        '                                        </select>\n' +
        '                                    </div>\n' +
        '                                </div>\n' +
        '                            </div>\n' +
        '\n' +
        '                            <label class="layui-form-label">上级党组织</label>\n' +
        '                            <div class="layui-input-inline">\n' +
        '                                <div class="layui-inline" style="width: 100%;">\n' +
        '\n' +
        '                                    <div class="layui-input-inline" style="width: 100%;">\n' +
        '                                        <select name="superiorBranch" id="superiorBranch" lay-verify="required" lay-search="" style="width: 100%;">\n' +
        '                                        </select>\n' +
        '                                    </div>\n' +
        '                                </div>\n' +
        '                            </div>\n' +
        '                        </div>\n' +
        '\n' +
        '\n' +
        '\n' +
        '                        <div class="layui-form-item layui-form-text">\n' +
        '                            <label class="layui-form-label">地址</label>\n' +
        '                            <div class="layui-input-inline" style="width: 500px;">\n' +
        '                                <input type="text" name="address" value='+ data.address +'  lay-verify="required"\n' +
        '                                       autocomplete="off" class="layui-input">\n' +
        '                            </div>\n' +
        '\n' +
        '\n' +
        '                        </div>\n' +
        '\n' +
        '                        <div class="layui-form-item layui-form-text">\n' +
        '                            <label class="layui-form-label">党组织类别</label>\n' +
        '                            <div class="layui-input-block">\n' +
        '                                <input type="text" name="branchCategory" value='+ data.branchCategory +'  lay-verify="required"\n' +
        '                                       autocomplete="off" class="layui-input">\n' +
        '                            </div>\n' +
        '                        </div>\n' +
        '\n' +
        '                        <div class="layui-form-item layui-form-text">\n' +
        '                            <label class="layui-form-label">党组织书记</label>\n' +
        '                            <div class="layui-input-inline" style="width: 30%;">\n' +
        '                                <input type="text" name="partyOrganizationSecretary" value='+ data.partyOrganizationSecretary +'  lay-verify="required"\n' +
        '                                       autocomplete="off" class="layui-input">\n' +
        '                            </div>\n' +
        '\n' +
        '                            <label class="layui-form-label">党组织书记电话号码&nbsp;</label>\n' +
        '                            <div class="layui-input-inline" style="width: 30%;">\n' +
        '                                <input type="text" name="secretaryTelephone" value='+ data.secretaryTelephone +'  lay-verify="required"\n' +
        '                                       autocomplete="off" class="layui-input">\n' +
        '                            </div>\n' +
        '                        </div>\n' +
        '\n' +
        '\n' +
        '\n' +
        '                        <div class="layui-form-item layui-form-text">\n' +
        '                            <label class="layui-form-label">成立时间</label>\n' +
        '                            <div class="layui-input-inline">\n' +
        '                                <input type="text" name="establishmentDate" id="establishmentDate" value='+ data.establishmentDate +'   lay-verify="required"\n' +
        '                                       autocomplete="off" class="layui-input">\n' +
        '                            </div>\n' +
        '                        </div>\n' +
        '\n' +
        '                        <div class="layui-form-item">\n' +
        '                            <label class="layui-form-label">&nbsp;</label>\n' +
        '                            <div class="layui-input-block">\n' +
        '                                <input type="checkbox" name="isHaveFirstsecretary" id="isHaveFirstsecretary"  title="是否有第一书记">\n' +
        '                                <input type="checkbox" name="isHaveParttime" id="isHaveParttime" title="是否有兼职委员">\n' +
        '                                <input type="checkbox" name="isHaveEducationplace" id="isHaveEducationplace" title="是否有教育站点">\n' +
        '                            </div>\n' +
        '                        </div>\n' +
        '\n' +
        '                        <div class="layui-form-item layui-form-text">\n' +
        '                            <label class="layui-form-label">党组织联系人</label>\n' +
        '                            <div class="layui-input-inline">\n' +
        '                                <input type="text" name="partyOrganizationContact" value='+ data.partyOrganizationContact +' lay-verify="required"\n' +
        '                                       autocomplete="off" class="layui-input">\n' +
        '                            </div>\n' +
        '\n' +
        '                            <label class="layui-form-label">党组织联系电话</label>\n' +
        '                            <div class="layui-input-inline">\n' +
        '                                <input type="text" name="contactTelephone" value='+ data.contactTelephone +'  lay-verify="required"\n' +
        '                                       autocomplete="off" class="layui-input">\n' +
        '                            </div>\n' +
        '\n' +
        '                            <label class="layui-form-label">党组织人数</label>\n' +
        '                            <div class="layui-input-inline">\n' +
        '                                <input type="text" name="number" value='+ data.number +'  lay-verify="required"\n' +
        '                                       autocomplete="off" class="layui-input">\n' +
        '                            </div>\n' +
        '                        </div>\n' +
        '\n' +
        '\n' +
        '\n' +
        '\n' +
        '                        <div class="layui-form-item" style="text-align: center">\n' +
        '                            <div class="layui-input-block">\n' +
        '                                <button class="layui-btn" lay-submit lay-filter="ok">提交</button>\n' +
        '                                <button type="reset" class="layui-btn layui-btn-primary" id="reset">重置</button>\n' +
        '                            </div>\n' +
        '                        </div>\n' +
        '\n' +
        '\n' +
        '                    </div>\n' +
        '                </div>\n' +
        '            </form>';


        return s;
    }


</script>

<script type="text/html" id="dothing">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>

    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
